package part8;

/**
 * @author wcj
 * @Date 2021/5/16 18:14
 * @Version 1.0
 */
public class Part88 {

    public static void main(String[] args) {
        Mill mill = new Mill();
        Grain g = mill.process();
        System.out.println(g);
        WheatMill wheatMill = new WheatMill();
        Wheat w = wheatMill.process();
        System.out.println(w);
    }
}

class Grain {
    @Override
    public String toString() {
        return "Grain";
    }
}

class Wheat extends Grain {
    @Override
    public String toString() {
        return "Wheat";
    }
}

class Mill {
    Grain process() {
        return new Grain();
    }
}

class WheatMill extends Mill {

    /**
     * 协变返回类型，即重写方法能够返回基类方法的导出类型
     *
     * @return
     */
    @Override
    Wheat process() {
        return new Wheat();
    }
}